package com.ym.manager.admin.complain;

import com.ym.manager.admin.complain.vo.ComplainListVo;
import com.ym.utils.Pages;
import com.ym.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @Author: dhf
 * @ClassName: ComplainController
 * @Date: 2022/9/23 20:53
 * @Description: 投诉
 * @Version: 1.0
 */
@Controller
@RequestMapping("/complain/")
public class ComplainController {
    @Autowired
    private ComplainService complainService;
    @RequestMapping("/index")
    public String index(){
        return "/complain/list";
    }


    @RequestMapping("/list")
    @ResponseBody
    public String list(ComplainListVo complainListVo,@RequestParam(defaultValue = "0") int start,
                       @RequestParam(defaultValue = "10")int length){
        Map<String,Object> result = ResultUtil.result();
        try {
            Pages<Map<String,Object>> pages = complainService.getList(complainListVo,start,length);
            //查询数据
            result.put("data",pages.getList());
            result.put("count",pages.getTotal());
            result.put("recordsTotal",pages.getTotal());
            result.put("recordsFiltered",pages.getTotal());
        }catch (Exception e){
            e.printStackTrace();
            result.put("code",-1000);
            result.put("msg","系统异常");
        }
        return ResultUtil.toJSON(result);
    }

    @RequestMapping("/complainOpt")
    @ResponseBody
    public String complainOpt(String id,int status){
        Map<String,Object> map = ResultUtil.result();
        try{
            complainService.complainOpt(id,status);
        }catch (Exception e){
            map.put("code",-1);
            map.put("msg",e.getMessage());
        }

        return ResultUtil.toJSON(map);
    }

    @RequestMapping("/del")
    @ResponseBody
    public String complainDel(long id) {
        Map<String,Object> map = ResultUtil.result();
        try{
            complainService.complainDel(id);
        }catch (Exception e){
            map.put("code",-1);
            map.put("msg",e.getMessage());
        }
        return ResultUtil.toJSON(map);
    }
}
